package com.gusto.samples.cluster;

import java.util.List;

import org.apache.log4j.Logger;
import org.jfree.chart.JFreeChart;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.gusto.engine.clusterant.algorithms.antsclustering.PlanObject;
import com.gusto.engine.clusterant.algorithms.kmeansclustering.ClusterObject;
import com.gusto.engine.clusterant.graph.ClusterPlanGraph;
import com.gusto.engine.clusterant.rmi.AntsClusteringRMI;
import com.gusto.engine.clusterant.rmi.KMeansClusteringRMI;

public class DisplaySample {
	
	private Logger log = Logger.getLogger(getClass());
	
	public void test_display() {
		ApplicationContext factory = new ClassPathXmlApplicationContext("config-display.xml");
		AntsClusteringRMI antsClustering = (AntsClusteringRMI)factory.getBean("antsClusteringRMI");
		KMeansClusteringRMI kmeansClustering = (KMeansClusteringRMI)factory.getBean("kmeansClusteringRMI");
		
		PlanObject plan = antsClustering.getPlan();
		log.info(plan);
		
		List<ClusterObject> clusters = kmeansClustering.cluster(plan.getPoints());
		
		/**/
		JFreeChart chart = ClusterPlanGraph.getClusterPlanScatterPlotGraph(clusters);
		ClusterPlanGraph.displayAsSwing(chart);
		/**/
		
		/*
		ChartFrame frame = new ChartFrame("Clustering", chart);
    	frame.pack();
    	frame.setVisible(true);
    	*/ 
	}
	
	public static void main(String[] args) throws InterruptedException {
		 DisplaySample sample = new DisplaySample();
		 sample.test_display();
	}
	
}
